package cn.doitedu.pekko;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: deep as the sea
 * @Site: <a href="www.doe.top">多易教育-易学堂</a>
 * @QQ: 657270652
 * @Date: 2024/2/12
 * @Desc:
 *  用线程来进行并发性能测试
 **/
public class Demo3 {

    public static void main(String[] args) {

        AtomicInteger counter =  new AtomicInteger(0);


        System.out.println(System.currentTimeMillis()/1000 + ": 任务开始");

        for (int i = 0; i < 1000000; i++) {
            new Thread(new MyTask(counter)).start();
        }



        while(true){
            if(counter.get() == 1000000){
                System.out.println(System.currentTimeMillis()/1000 + ": 任务全部完成");
                break;
            }
        }

    }

}

class MyTask implements Runnable{

    AtomicInteger counter;

    public MyTask(AtomicInteger counter) {
        this.counter = counter;
    }

    @Override
    public void run() {
       counter.incrementAndGet();
    }
}